"""
Problem 99: https://projecteuler.net/problem=99

Comparing two numbers written in index form like 2'11 and 3'7 is not difficult, as any
calculator would confirm that 2^11 = 2048 < 3^7 = 2187.

However, confirming that 632382^518061 > 519432^525806 would be much more difficult, as
both numbers contain over three million digits.

Using base_exp.txt, a 22K text file containing one thousand lines with a base/exponent
pair on each line, determine which line number has the greatest numerical value.
"""


# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/6/9
'''


from math import log10
DataFile = 'p099_base_exp.txt'


def readData(filepath: str = DataFile) -> list:
    data = []
    with open(filepath, 'r') as fp:
        for line in fp:
            linedata = eval('[' + line.strip() + ']')
            data.append(linedata)

    return data


Data = readData(DataFile)


def solution(data: list = Data):
    res = (0, data[0][1]*log10(data[0][0]))
    for i in range(1, len(data)):
        tmp = data[i][1]*log10(data[i][0])
        if tmp > res[1]:
            res = (i, tmp)

    return res[0]+1, data[res[0]]  # line = 1,2,3...


if __name__ == "__main__":
    import doctest
    doctest.testmod(verbose=False)

    print(solution())
    # (709, [895447, 504922])
